import {useEffect, useState} from 'react'
import {GetAllShippingCompanys,} from '@/api/project'
import {findByIdFactory, isSuccessRes} from "@/types/common";
import {sleep} from "@/types/jsUtil";
import {useRequest} from "ahooks";

interface ExpressCompany {

}

export const useCompanyList = () => {

  const req = useRequest<{ label: string, value: number }[]>(
    () => GetAllShippingCompanys().then(async (res) => {
      if (isSuccessRes(res)) {
        return res.Result.map(e =>
          ({
            label: e.Name,
            value: e.ShippingCompanyID
          })
        )
      }
    }),
    {
      cacheKey: 'useCompanyList',
      loadingDelay: 1000,
      cacheTime: -1,
      staleTime: -1
    },
  );

  const {params, data, loading} = req

  return {
    req,
    expressCompanySelectProps: {
      options: data,
      loading,
    },
    findById: findByIdFactory(data)
  }
}
